package com.example.administrator.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.myapplication.Util.DB;

public class MainActivity extends AppCompatActivity {

    private EditText usernameEd;
    private EditText studentidEd;
    private Button loginBtn;
    private TextView forgetStudentTv;
    private TextView signInTv;
    private String usernameStr;
    private String studentidStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initEvent();
    }
    private void initView(){
        usernameEd = findViewById(R.id.username_et);
        studentidEd = findViewById(R.id.student_id_et);
        loginBtn = findViewById(R.id.login_btn);
        forgetStudentTv = findViewById(R.id.forget_student_id_tv);
        signInTv = findViewById(R.id.sign_in_tv);
    }
    private  void initData(){
        usernameStr = usernameEd.getText().toString()+"";
        studentidStr = studentidEd.getText().toString()+"";
    }
    private  void initEvent(){
   loginBtn.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View view) {
             initData();
           DB db = new DB(MainActivity.this);
           Boolean result = db.loginSelect(usernameStr,studentidStr);
           if(result){
               Toast.makeText(MainActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
           }else{
               Toast.makeText(MainActivity.this,"登录失败",Toast.LENGTH_SHORT).show();
           }

       }
   });
   forgetStudentTv.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View view) {

       }
   });
   signInTv.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View view) {
           Intent intent = new Intent(MainActivity.this,SignInActivity.class);
           startActivity(intent);
       }
   });

    }
}
